package 力扣日常刷题.木23一月.第08天308;

import java.util.ArrayList;
import java.util.Arrays;

/**
 * @author 帅小伙
 * @date 2022/3/8
 * @description
 */
public class Demo18和为s的两个数字 {


    public int[] twoSum(int[] nums, int target) {
        Arrays.sort(nums);
        int l = 0,r = nums.length - 1;
        while(l < r) {
            int sum = nums[l] + nums[r];
            if(sum == target) return new int[]{nums[l],nums[r]};
            else if(sum > target) r--;
            else l++;
        }
        return new int[0];
    }
}
